<?php
	/**
	 * 获取用户邮件列表列表
	 */
    class EmailDetail extends APIBase {
		
		public $tag = "EmailDetail";
    	public $isLogin = true;
		
		public function before() {
			$this->initCacheRedis();
			$this->initMysql();
			return true;
		}
		public function logic(){
			$ID = $this->param['id'];
			if($ID==""||$ID==0){
				$this->returnError(303,'ID is null');
			}
			$playerID = $this->uid;
			$UserEmailList = $this->cache_redis->keys("hUserEmailList:$playerID:*");
			if(!empty($UserEmailList)){
				$count = count($UserEmailList);
				$result = array();
			    if ($count) {
				    for($i=0;$i<$count;$i++){ 
					    $list = $this->cache_redis->hGetAll("hUserEmailList:$playerID:".$i);
                     	if($list['id']==$ID && $list['uid']==$playerID){
							if($list['type']==1){//排行榜
								$boardreward = $this->cache_redis->hGetAll("hboardreward:".$list['rewardid']);
								$list['reward'] = $boardreward['reward'];
							}elseif($list['type']==2){//签到
								$signreward = $this->cache_redis->hGetAll("hsignreward:".$list['rewardid']);
								$list['reward'] = $signreward['reward'];
							}elseif($list['type']==3){//抽奖
								$rewardpool = $this->cache_redis->hGetAll("hrewardpool:".$list['rewardid']);
								$list['reward'] = $rewardpool['reward'];
							}elseif($list['type']==4){//分享
								$sharereward = $this->cache_redis->hGetAll("hsharereward:".$list['rewardid']);
								$list['reward'] = $sharereward['reward'];
							}elseif($list['type']==5){//首次被邀请
								$sharereward = $this->cache_redis->hGetAll("hsharereward:".$list['rewardid']);
								$list['reward'] = $sharereward['reward'];
							}
							$rewardlist = json_decode($list['reward'],true);
				            $rewardrow = array();
				            foreach($rewardlist as $key=>$val){
					            $proplist = $this->cache_redis->hGetAll("prop:".$key);
					            $rewardrow[] = array("name"=>$proplist['name'],"count"=>$val);
							}
							$msg = $this->cache_redis->hGetAll("hmg:".$list['mid']);
							$list['content'] = $msg['content'];
							$result = array('id'=>$ID,'content'=>$list['content'],'reward'=>$rewardrow);
							$time = time();
							//$this->mysql->query("update mail_send set is_read = 1,update_date=$time where id = $ID");
							$this->cache_redis->hMset("hUserEmailList:$playerID:".$i,array("readstatus"=>1));
						}		 
				    }
					$this->returnData($result);
	            }
				
			}else{
				$this->returnError(301,"数据异常");
			}
			
		}
		
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
